package com.glasses.business.activity;

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.glasses.business.R;
import com.glasses.business.event.BussEvent;
import com.glasses.business.http.NetUtils;
import com.glasses.business.utils.Tools;

import net.neiquan.okhttp.NetCallBack;
import net.neiquan.okhttp.ResultModel;

import org.haitao.common.utils.ToastUtil;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import de.greenrobot.event.EventBus;

/**
 * Author：邓勇军
 * English Name：Deng,The Sky Fucker!
 * Email：dandycoder@126.com
 * Date：2017/3/10
 * Version：1.0
 */

public class BackMoneyActivity_ extends Activity {
    @InjectView(R.id.back_img)
    ImageView backImg;
    @InjectView(R.id.title_tv)
    TextView titleTv;
    @InjectView(R.id.backSure)
    TextView backSure;
    @InjectView(R.id.addrTv)
    TextView addrTv;
    @InjectView(R.id.transpCompany)
    EditText transpCompany;
    @InjectView(R.id.transpOrderNum)
    EditText transpOrderNum;
    private int id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
//                WindowManager.LayoutParams.FLAG_FULLSCREEN);  //全屏
        setContentView(R.layout.activity_back_money_);
        ButterKnife.inject(this);
        titleTv.setVisibility(View.VISIBLE);
        titleTv.setText("售后申请");
        if (getIntent() != null) {
            id = getIntent().getIntExtra("id", 0);
        }
        NetUtils.getInstance().systemContent(2, new NetCallBack() {
            @Override
            public void onSuccess(String response, String mssage, ResultModel model) {
                addrTv.setText(response);
            }

            @Override
            public void onFail(boolean dataError, int errorCode, String mssage) {

            }
        }, null);
    }

    @OnClick({R.id.back_img, R.id.backSure})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back_img:
                finish();
                break;
            case R.id.backSure:
                String company = transpCompany.getText().toString();
                String orderNum = transpOrderNum.getText().toString();
                if (TextUtils.isEmpty(company)) {
                    ToastUtil.shortShowToast("请先填写快递公司...");
                } else if (TextUtils.isEmpty(orderNum)) {
                    ToastUtil.shortShowToast("请先填写运单号...");
                } else {
                    Tools.showDialog(this);
                    NetUtils.getInstance().backMoney(id, company, orderNum, 2, new NetCallBack() {
                        @Override
                        public void onSuccess(String response, String mssage, ResultModel model) {
                            Tools.dismissWaitDialog();
                            ToastUtil.shortShowToast(mssage);
                            EventBus.getDefault().post(new BussEvent(BussEvent.Order_Refush));
                            finish();
                        }

                        @Override
                        public void onFail(boolean dataError, int errorCode, String mssage) {
                            Tools.dismissWaitDialog();
                            ToastUtil.shortShowToast(mssage);
                        }
                    }, null);
                }
                break;
        }
    }
}
